package org.come.Jpanel;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import org.come.model.Eshop;
import org.come.until.CutButtonImage;
import org.come.until.DeviceEshopUntil;

import com.tool.btn.TaoBaoBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

public class ShopHomePageJpanel extends JPanel {


    /** 7-17-HGC-start */
    // private TaoBaoBtn[] menuLable = new TaoBaoBtn[6];
    /**
     * 推荐recommendMenuBtn<br>
     * 上款newMenuBtn<br>
     * 折扣discountMenuBtn<br>
     * 药品pharmaceuticalsMenuBtn<br>
     * 宝鉴treasureMenuBtn<br>
     */
    private TaoBaoBtn recommendMenuBtn, pharmaceuticalsMenuBtn, treasureMenuBtn,newMenuBtn, discountMenuBtn;

    /** 7-17-HGC-end */
    private GoodsTJMinJpanel[] goodsTJMinJpanels = new GoodsTJMinJpanel[3]; //
    private TaoBaoBtn btnhp,// 首页
            btnep,// 末页
            btnsyy,// 上一页
            btnxyy;// 下一页
    private JLabel labpage; // 放置当前页数和总页数
    private int nowPage = 1; // 当前页数
    private int maxPage = 1; // 最大页码
    /** "推荐"-40, "上款"-41, "折扣"-42"药品"-43, "宝鉴"-44*/
    private int shopType1 = 40;

    public ShopHomePageJpanel() {
            this.setLayout(null);
            this.setPreferredSize(new Dimension(802, 538));
            this.setOpaque(false);
            this.setBackground(UIUtils.Color_BACK);
            labpage = new JLabel("1/1", SwingConstants.CENTER);
            labpage.setForeground(Color.white);
            labpage.setBounds(425, 435, 0, 0);
            labpage.setFont(UIUtils.TEXT_FONT1);
            this.add(labpage);
            // 首页
            btnhp = new TaoBaoBtn("inkImg/number/b8/shou.png", 1, "", 50, this);
            btnhp.setBounds(338, 435, 0, 0);
            this.add(btnhp);
            // 上一页
            btnsyy = new TaoBaoBtn("inkImg/number/b8/btn2-left.png", 1, "", 51, this);
            btnsyy.setBounds(138, 250, 25, 75);
            this.add(btnsyy);
            // 下一页
            btnxyy = new TaoBaoBtn("inkImg/number/b8/btn2-right.png", 1, "", 52, this);
            btnxyy.setBounds(770, 250, 25, 75);
            this.add(btnxyy);
            // 末页
            btnep = new TaoBaoBtn("inkImg/number/b8/wei.png", 1, "", 53, this);
            btnep.setBounds(520, 435, 0, 0);
            this.add(btnep);
            /** 7-17-HGC-start */
            // String[] menuStr = new String[] { "珍品", "技能", "神兽", "仙器", "配饰", "积分"
            // };
            // // 设置菜单按钮监听
            // for (int i = 0; i < menuStr.length; i++) {
            // menuLable[i] = new TaoBaoBtn("skin/8100226/button/3.png", 1, menuStr[i], i
            // + 10, this);
            // menuLable[i].setBounds(54 + i * 77, 14, 63, 26);
            // this.add(menuLable[i]);
            // }
            // try {
            // menuLable[0].setIcons(CutButtonImage.cuts("skin/8100226/button/4.png"));
            // } catch (Exception e) {
            // e.printStackTrace();
            // }
             getRecommendMenuBtn();
              getNewMenuBtn();
              getDiscountMenuBtn();
              getPharmaceuticalsMenuBtn();
              getTreasureMenuBtn();
            /** 7-17-HGC-end */
            getShopGoodsView(this, DeviceEshopUntil.getShopingMenuRecommendJpanel());

    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        	if (icon == null) {
                icon = CutButtonImage.getImage("inkImg/number/b8/ZYGG.png", 640, 139);
            }
            g.drawImage(icon.getImage(), 144, -1, 640, 139, this);

    }



    /** 初始化商品 */
    public void getShopGoodsView(ShopHomePageJpanel shopHomePageJpanel, List<Eshop> eshopList) {
    		maxPage = eshopList.size() % 3 == 0 ? eshopList.size() / 3 : eshopList.size() / 3 + 1;
            labpage.setText(nowPage + "/" + maxPage);
            for (int i = 3 * (nowPage - 1); i < 3 * nowPage; i++) {
                int row = i / 3;
                int rank = i % 3;
                if (i >= eshopList.size()) {
                    break;
                }
                goodsTJMinJpanels[i] = new GoodsTJMinJpanel(eshopList.get(i));
                goodsTJMinJpanels[i].setBounds(169 + rank * 204, 155 + row * 110, 190, 250);//修改

                shopHomePageJpanel.add(goodsTJMinJpanels[i]);
            }

    }

    public void isShopGoods1(int shopType1) {

        this.shopType1 = shopType1;
        /** "推荐"-40, "上新"-41, "折扣"-42, "药品"-43, "宝鉴"-44*/
        switch (shopType1) {
        case 40:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuRecommendJpanel());
            break;
        case 41:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuNewJpanel());
            break;
        case 42:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuDiscountJpanel());
            break;
        case 43:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuPharmaceuticalsJpanel());
            break;
        case 44:
            changeShopGoodsView(DeviceEshopUntil.getShopingMenuTreasureJpanel());
            break;

        default:
            break;
        }
    }

    /** 更换展示的商品 */
    public void changeShopGoodsView(List<Eshop> eshopList) {
        for (int i = 0; i < goodsTJMinJpanels.length; i++) {
            goodsTJMinJpanels[i].clearView();
        }
        maxPage = eshopList.size() % 3 == 0 ? eshopList.size() / 6 : eshopList.size() / 3 + 1;
        labpage.setText(nowPage + "/" + maxPage);
        int num = 0;
        for (int i = 3 * (nowPage - 1); i < 3 * nowPage; i++) {
            if (i >= eshopList.size()) {
                break;
            }
            goodsTJMinJpanels[num].addEshopMessage(eshopList.get(i));
            num++;
        }
    }

    public int getShopType1() {
        return shopType1;
    }

    public void setShopType1(int shopType1) {
        this.shopType1 = shopType1;
    }

    public GoodsTJMinJpanel[] getGoodsTJMinJpanels() {
        return goodsTJMinJpanels;
    }

    public void setGoodsTJMinJpanels(GoodsTJMinJpanel[] goodsTJMinJpanels) { this.goodsTJMinJpanels = goodsTJMinJpanels;}

    public TaoBaoBtn getBtnhp() {
        return btnhp;
    }

    public void setBtnhp(TaoBaoBtn btnhp) {
        this.btnhp = btnhp;
    }

    public TaoBaoBtn getBtnep() {
        return btnep;
    }

    public void setBtnep(TaoBaoBtn btnep) {
        this.btnep = btnep;
    }

    public TaoBaoBtn getBtnsyy() {
        return btnsyy;
    }

    public void setBtnsyy(TaoBaoBtn btnsyy) {
        this.btnsyy = btnsyy;
    }

    public TaoBaoBtn getBtnxyy() {
        return btnxyy;
    }

    public void setBtnxyy(TaoBaoBtn btnxyy) {
        this.btnxyy = btnxyy;
    }

    public JLabel getLabpage() {
        return labpage;
    }

    public void setLabpage(JLabel labpage) {
        this.labpage = labpage;
    }

    public int getNowPage() {
        return nowPage;
    }

    public void setNowPage(int nowPage) {
        this.nowPage = nowPage;
    }

    public int getMaxPage() {
        return maxPage;
    }

    public void setMaxPage(int maxPage) {
        this.maxPage = maxPage;
    }

    public TaoBaoBtn getRecommendMenuBtn() {
    		if (recommendMenuBtn == null) {
                recommendMenuBtn = new TaoBaoBtn("inkImg/number/b8/hometj1.png", 1, "", 44, this);
                recommendMenuBtn.setBounds(144, 420, 124, 72);
                this.add(recommendMenuBtn);
            }

        return recommendMenuBtn;
    }

    public void setRecommendMenuBtn(TaoBaoBtn recommendMenuBtn) {
        this.recommendMenuBtn = recommendMenuBtn;
    }

    public TaoBaoBtn getNewMenuBtn() {
    		if (newMenuBtn == null) {
                newMenuBtn = new TaoBaoBtn("inkImg/number/b8/homexp.png", 1, "", 45, this);
                newMenuBtn.setBounds(144 + 1 * 129, 420, 124, 72);
                this.add(newMenuBtn);
            }

        return newMenuBtn;
    }

    public void setNewMenuBtn(TaoBaoBtn newMenuBtn) {
        this.newMenuBtn = newMenuBtn;
    }

    public TaoBaoBtn getDiscountMenuBtn() {
    		if (discountMenuBtn == null) {
                discountMenuBtn = new TaoBaoBtn("inkImg/number/b8/homezk.png", 1, "", 46, this);
                discountMenuBtn.setBounds(144 + 2 * 129, 420, 124, 72);
                this.add(discountMenuBtn);
            }

        return discountMenuBtn;
    }

     public void setDiscountMenuBtn(TaoBaoBtn discountMenuBtn) { this.discountMenuBtn = discountMenuBtn; }



    public TaoBaoBtn getPharmaceuticalsMenuBtn() {
        if (pharmaceuticalsMenuBtn == null) {
            pharmaceuticalsMenuBtn = new TaoBaoBtn("inkImg/number/b8/homeyp.png", 1, "", 47, this);
            pharmaceuticalsMenuBtn.setBounds(144 + 3 * 129, 420, 124, 72);
            this.add(pharmaceuticalsMenuBtn);
        }

        return pharmaceuticalsMenuBtn;
    }

    public void setPharmaceuticalsMenuBtn(TaoBaoBtn pharmaceuticalsMenuBtn) {
        this.pharmaceuticalsMenuBtn = pharmaceuticalsMenuBtn;
    }

    public TaoBaoBtn getTreasureMenuBtn() {
        if (treasureMenuBtn == null) {
            treasureMenuBtn = new TaoBaoBtn("inkImg/number/b8/homeljbj.png", 1, "", 48, this);
            treasureMenuBtn.setBounds(144 + 4 * 129, 420, 124, 72);
            this.add(treasureMenuBtn);
        }

        return treasureMenuBtn;
    }

    public void setTreasureMenuBtn(TaoBaoBtn treasureMenuBtn) { this.treasureMenuBtn = treasureMenuBtn; }







}
